package com.ljy.my_study.leetcode.买卖股票的最佳时机II;

/**
 * @author lijunying
 * @date 2021/11/18 14:00
 */
public class TestMain2 {

//    贪心算法
    public int maxProfit(int[] prices) {
        int ans = 0;
        int n = prices.length;
        for (int i = 1; i < n; ++i) {
            ans += Math.max(0, prices[i] - prices[i - 1]);
        }
        return ans;
    }
}
